package com.huahai.config;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * 只要Sentinel保护的接口资源被访问，Sentinel就会调用 该{@link RequestOriginParser} 的实现类去解析访问来源
 */
//@Component
public class ConcreteRequestOriginParser implements RequestOriginParser {
    public String parseOrigin(HttpServletRequest httpServletRequest) {
        String serviceName = httpServletRequest.getParameter("serviceName");
        if (serviceName == null){
            throw new RuntimeException("sorry ,no parameter named serviceName is found");
        }

        return serviceName;
    }
}
